<?php
class Electric_charge_model extends CI_Model {
	
	private $tbl_data= 'TRN_ELECTRIC_CHARGE';
 
	public function __construct()
	{
		parent::__construct();
	}
	function get_all($fccode,$bdcode,$year){
		 $condition=" where b.fccode='".$fccode."'";
		 $condition.=" and a.entry_year=".$year;
		 $condition.=" and b.bdcode=".$bdcode;
		 return "select  A.TRNNO,A.ENTRY_YEAR,A.ENTRY_MONTH,A.ENTRY_DATE,B.METER_NO,A.MRCODE,A.METER_UNIT,A.TOTAL_ELEC_ENERGY,A.SERVICE_RATE
                ,A.TOTAL_FT,A.TOTAL_ELECTRIC,A.TOTAL_VAT,A.AMOUNT,A.MMCODE from  TRN_ELECTRIC_CHARGE A
                INNER JOIN  MST_METER_MASTER  B ON A.mmcode=B.mmcode ".$condition;
	}
	
	function count_all(){
		return $this->db->count_all($this->tbl_data);
	}
	
	function get_by_id($id){
		$this->db->where('TRNNO', $id);
		return $this->db->get($this->tbl_data)->row();
	 
	}
	function save($item){		
		$this->db->insert($this->tbl_data, $item);	
		return $this->db->insert_id();		
	}
	
	function update($item,$id){
		$this->db->where('TRNNO', $id);
		$this->db->update($this->tbl_data, $item);
	}
	
	function delete($id){
		$this->db->where('TRNNO', $id);
		$this->db->delete($this->tbl_data);
	}
	
 
}
?>